﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using qiupeng.Public;
using System.IO;
public partial class OpenWindows_open_YuanGong_HtManage : System.Web.UI.Page
{
    Db List = new Db();
    BindDrowDownList list = new BindDrowDownList();
    public static string CountsLabel, AllPageLabel, CurrentlyPageLabel, SqlStrStart, SqlStrMid, SqlStr, SqlStrStartCount, SqlStrCount;
    public string urlstr, keystr;
    public string CreateMidSql()
    {
        string MidSql = string.Empty;
        if (Request.QueryString["key"] != null)
        {
            if (Request.QueryString["Name"].ToString() != "")
            {
                MidSql = MidSql + " and XingMing like '%" + List.GetFormatStr(Server.UrlDecode(Request.QueryString["Name"])) + "%'";
            }

            //if (Request.QueryString["Unit"].ToString() != "")
            //{
            //    MidSql = MidSql + " and YinPinBMId = '" + List.GetFormatStr(Server.UrlDecode(Request.QueryString["Unit"])) + "'";
            //}
        }
        return MidSql;

    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            name.Attributes["onkeydown"] = "if (event.keyCode==13) { document.all.Button4.click(); return false;}";
            requeststr.Text = Server.UrlDecode(Request.QueryString["requeststr"].ToString());
        }

        if (Request.QueryString["Unit"] != null)
        {
            urlstr = "&BuMenId=" + Request.QueryString["Unit"].ToString() + "";

            string keyqx;
            string SQL_GetList = "select * from qp_hr_JiGou  where id='" + List.GetFormatStr(Request.QueryString["Unit"]) + "'";
            OleDbDataReader NewReader = List.GetList(SQL_GetList);
            if (NewReader.Read())
            {
                keyqx = NewReader["QxString"].ToString();
                keystr = "and  CHARINDEX('" + keyqx + "',(select QxString from qp_hr_JiGou where qp_hr_JiGou.id=qp_hr_Staff.YinPinBMId)) > 0 ";
            }

            NewReader.Close();
        }
        else
        {
            urlstr = "";

            keystr = " and YinPinBMId in (" + Session["bmqxa"].ToString().Trim() + ")";
        }


        string sql_down_bh = "select id,Linew+JgName as aaa  from qp_hr_JiGou  where id in (" + Session["bmqxa"].ToString().Trim() + ") order by QxString asc";

        if (!IsPostBack)
        {
            list.Bind_DropDownList_kong(Unit, sql_down_bh, "id", "aaa");
        }

        DataBindToGridview();
    }

    public void DataBindToGridview()
    {
        SqlStrStart = "select * from  qp_hr_Staff where 1=1 and YgZhuangTai='在职' " + keystr + " ";


        SqlStrMid = string.Empty;
        SqlStrMid = CreateMidSql();
        SqlStr = SqlStrStart + SqlStrMid;//查询


        if (Request.QueryString["key"] != null)
        {


            string SQL_GetList_xs = "" + SqlStr + " ";
            //  Response.Write(SQL_GetList_xs);
            GridView1.DataSource = List.GetGrid_Pages_not(SQL_GetList_xs);
            GridView1.DataBind();

        }
        else
        {
            string SQL_GetList_xs = "select * from qp_hr_Staff  where   YgZhuangTai='在职' " + keystr + " ";
            GridView1.DataSource = List.GetGrid_Pages_not(SQL_GetList_xs);
            GridView1.DataBind();

        }





    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GridView1.PageIndex = e.NewPageIndex;
        DataBindToGridview();
        this.GridView1.DataBind();
    }

    protected void Button4_Click(object sender, EventArgs e)
    {
        Response.Redirect("open_YuanGong_HtManage.aspx?key=1&name=" + name.Text + "&Unit=" + Unit.SelectedValue + "&requeststr=" + Server.UrlDecode(Request.QueryString["requeststr"].ToString()) + "");
    }
}
